package com.wanmait.recruitment.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.recruitment.pojo.Userinfo;
import com.wanmait.recruitment.service.ConfigService;
import com.wanmait.recruitment.service.UserinfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
@Controller
@RequestMapping("manage/userinfo")
public class UserinfoListController {
    @Resource
    private UserinfoService userinfoService;
    @Resource
    private ConfigService configService;
    @RequestMapping("list")
    public void userinfoList(){

    }
    @RequestMapping("date")
    public ModelAndView date(String pageNumber,Userinfo userinfo){
        ModelAndView modelAndView = new ModelAndView();
        int pageSize;
        try {
            pageSize = Integer.parseInt(configService.getValueByKey("userinfo_config"));
        } catch (NumberFormatException e) {
            pageSize = Integer.parseInt(configService.getDefaultValueByKey("userinfo_config"));
        }
        int pageNum;
        try {
            pageNum = Integer.parseInt(pageNumber);
        } catch (Exception e) {
            pageNum = 1;
        }
        PageInfo<Userinfo> userinfoPageInfo = userinfoService.findPage(userinfo,pageNum,pageSize);
        modelAndView.addObject("userinfoPageInfo",userinfoPageInfo);
        return modelAndView;
    }
    @RequestMapping("del")
    @ResponseBody
    public void del(Userinfo userinfo){
        userinfoService.updateEnable(userinfo);
    }
    @RequestMapping("batchDel")
    @ResponseBody
    public void batchDel(String idArr){
        userinfoService.batchDel(idArr);
    }
    @RequestMapping("userinfoDetailed")
    public ModelAndView userinfoDetailed(Integer id){
        ModelAndView modelAndView = new ModelAndView();
        Userinfo userinfo = userinfoService.findById(id);
        modelAndView.addObject("userinfo",userinfo);
        return modelAndView;
    }
}
